package ER.diagram.part;

import java.util.Collections;
import java.util.List;

import org.eclipse.gef.Tool;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteGroup;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeConnectionTool;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeCreationTool;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;

import ER.diagram.providers.EntityRelationshipElementTypes;

/**
 * @generated
 */
public class EntityRelationshipPaletteFactory {

	/**
	 * @generated
	 */
	public void fillPalette(PaletteRoot paletteRoot) {
		paletteRoot.add(createER1Group());
	}

	/**
	 * Creates "ER" palette tool group
	 * @generated
	 */
	private PaletteContainer createER1Group() {
		PaletteGroup paletteContainer = new PaletteGroup(
				Messages.ER1Group_title);
		paletteContainer.setId("createER1Group"); //$NON-NLS-1$
		paletteContainer.add(createColumns1CreationTool());
		paletteContainer.add(createEntity2CreationTool());
		paletteContainer.add(createRelation3CreationTool());
		paletteContainer.add(createPrimaryKey4CreationTool());
		return paletteContainer;
	}

	/**
	 * @generated
	 */
	private ToolEntry createColumns1CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Columns1CreationTool_title,
				Messages.Columns1CreationTool_desc,
				Collections
						.singletonList(EntityRelationshipElementTypes.Columns_3001));
		entry.setId("createColumns1CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(EntityRelationshipElementTypes
				.getImageDescriptor(EntityRelationshipElementTypes.Columns_3001));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createEntity2CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Entity2CreationTool_title,
				Messages.Entity2CreationTool_desc,
				Collections
						.singletonList(EntityRelationshipElementTypes.Entity_2001));
		entry.setId("createEntity2CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(EntityRelationshipElementTypes
				.getImageDescriptor(EntityRelationshipElementTypes.Entity_2001));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createRelation3CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Relation3CreationTool_title,
				Messages.Relation3CreationTool_desc,
				Collections
						.singletonList(EntityRelationshipElementTypes.Relation_4001));
		entry.setId("createRelation3CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(EntityRelationshipElementTypes
				.getImageDescriptor(EntityRelationshipElementTypes.Relation_4001));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createPrimaryKey4CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.PrimaryKey4CreationTool_title,
				Messages.PrimaryKey4CreationTool_desc,
				Collections
						.singletonList(EntityRelationshipElementTypes.PrimaryKey_3002));
		entry.setId("createPrimaryKey4CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(EntityRelationshipElementTypes
				.getImageDescriptor(EntityRelationshipElementTypes.PrimaryKey_3002));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private static class NodeToolEntry extends ToolEntry {

		/**
		 * @generated
		 */
		private final List<IElementType> elementTypes;

		/**
		 * @generated
		 */
		private NodeToolEntry(String title, String description,
				List<IElementType> elementTypes) {
			super(title, description, null, null);
			this.elementTypes = elementTypes;
		}

		/**
		 * @generated
		 */
		public Tool createTool() {
			Tool tool = new UnspecifiedTypeCreationTool(elementTypes);
			tool.setProperties(getToolProperties());
			return tool;
		}
	}

	/**
	 * @generated
	 */
	private static class LinkToolEntry extends ToolEntry {

		/**
		 * @generated
		 */
		private final List<IElementType> relationshipTypes;

		/**
		 * @generated
		 */
		private LinkToolEntry(String title, String description,
				List<IElementType> relationshipTypes) {
			super(title, description, null, null);
			this.relationshipTypes = relationshipTypes;
		}

		/**
		 * @generated
		 */
		public Tool createTool() {
			Tool tool = new UnspecifiedTypeConnectionTool(relationshipTypes);
			tool.setProperties(getToolProperties());
			return tool;
		}
	}
}
